const dbutil = require('../../../libs/MyDB');

module.exports = {
    getTableInfo: async function () {
        let tables = [];
        await dbutil.multiSelect('res_tableinfo', ['table_id', 'table_number', 'table_usage','tabletype_people'])
            .then(
                result => {
                    tables = result;
                }
            )
        return {
            code: 0,
            msg: "查询成功",
            data: tables,
            count: tables.length,
        }
    },
    addTable: async function(data){
        await dbutil.singleSelect('res_tabletype','tabletype_id',`tabletype_people='${data.tabletype_people}'`)
            .then(
                res =>{
                    data.tabletype_id = res.tabletype_id
                }
            )
        delete data.tabletype_people;
        await dbutil.add('res_table',data);
        return {
            code:200,
            msg: '添加成功',
        }
    },
    editTable: async function(data){
        await dbutil.singleSelect('res_tabletype','tabletype_id',`tabletype_people='${data.tabletype_people}'`)
            .then(
                res =>{
                    data.tabletype_id = res.tabletype_id
                }
            )
        delete data.tabletype_people;
        await dbutil.update('res_table',`table_id=${data.table_id}`,data);

        return {
            code:200,
            msg: '修改成功',
        }
    },
    delTable: async function(data){
        await dbutil.del('res_table',`table_id=${data.table_id}`);

        return {
            code:200,
            msg: '删除成功',
        }
    }
}